<template>
  <router-layout>
    <div class="topicType">
      <!-- <TitleItem v-if="this.wx==true"></TitleItem> -->
      <!-- 右侧添加主题 -->
      <AddTheme></AddTheme>
      <div class="wapper-box">
        <div class="title">
          <img v-if="articleType" :src="articleType.file_path" alt srcset>
          <p class="typeName">#{{articleType.articletype_name}}#</p>
        </div>
        <!-- 话题列表 -->
        <div class="tab-box">
          <div>
            <!-- 暂无数据组件 -->
            <!-- <Nodata v-if="isNoData"></Nodata> -->
            <!-- <van-list v-else v-model="loading" :finished="finished" @load="onLoad" :offset="0"> -->
            <van-list v-model="loading" :finished="finished" @load="onLoad" :offset="0">
              <van-cell v-for="it in activeDataList" :key="it.id">
                <div class="content-box" @click="go_detail(it)">
                  <van-row type="flex" justify="space-between" align="center">
                    <van-col>
                      <div class="header">
                        <div class="name">
                          <img
                            :src="it.portrait?it.portrait:'https://gw.alicdn.com/tfs/TB15Q0lOmzqK1RjSZFHXXb3CpXa-400-400.png'"
                            alt
                            class="photo"
                            srcset
                          >
                        </div>
                        <div class="date">
                          <p class="dateName" style="line-height:12px;">{{it.create_username}}</p>
                          <span class="dateTime">{{it.create_time}}</span>
                        </div>
                      </div>
                    </van-col>
                    <van-col>
                      <div
                        v-if="!it.top_status==0"
                        class="stick"
                        style="line-height: 12px;  border: 1px solid #BCE4F9;"
                      >
                        <i>置顶</i>
                      </div>
                    </van-col>
                  </van-row>
                  <div class="title_topic" style="line-height:14px;">#{{it.articletype_name}}#</div>
                  <van-row
                    class="container-header"
                    type="flex"
                    justify="space-between"
                    align="bottom"
                  >
                    <van-col class="van-ellipsis">
                      <div class="content-title one-txt-cut">{{ it.article_title }}</div>
                      <div class="dict_text">
                        <p style="line-height:14px;">{{it.article_content}}</p>
                      </div>
                    </van-col>
                    <van-col>
                      <div class="content-img" v-if="it.file_path">
                        <img :src="it.file_path" width="100%" alt>
                      </div>
                    </van-col>
                  </van-row>
                  <div class="content-middle">
                    <van-row type="flex" justify="space-between">
                      <van-col>
                        <!-- <span>{{it.create_username}}</span>
                                        <span v-if="!it.top_status==0">
                                            <van-tag type="primary">置顶</van-tag>
                        </span>-->
                      </van-col>
                      <van-col>
                        <i class="title-user">
                          <span class="iconfont icon-dianzan"></span>
                          <span>{{it.like_nums || 0}}</span>
                        </i>
                        <i class="title-user">
                          <span class="iconfont icon-xiaoxi"></span>
                          <span>{{it.comment_nums || 0}}</span>
                        </i>
                      </van-col>
                    </van-row>
                  </div>
                </div>
              </van-cell>
            </van-list>
          </div>
        </div>
      </div>
    </div>
  </router-layout>
</template>
<script>
import { article_list } from "@/api/article";
import Nodata from "../public/nodata/Nodata"; // 导入暂无数据组件
import Backtop from "../public/backtop/Backtop"; //导入回到顶部
import AddTheme from "../public/mask/AddTheme"; // 导入发表主题
import TitleItem from "../../components/public/title/title";
export default {
  name: "component_name",
  components: { Backtop, Nodata, TitleItem, AddTheme },
  computed: {
    activeDataList: function () {
      return this.dataList.filter(function (item) {
        return item.close_status == 1
      })
    }
  },
  data() {
    return {
      isNoData: false,
      loading: false,
      finished: false,
      dataList: [],
      typeName: "",
      banner_path: "",
      articleType:{},
      total: "",
      listQuery: {
        current: 1,
        limit: 5,
        company_id: localStorage.getItem("companyId") || 1,
        articletype_id: this.$route.query.id
      }
    };
  },
  methods: {
    //跳转到详情页
    go_detail(it) {
      this.perId = it.id;
      this.$router.push({
        path: "/CommunityDetail",
        query: {
          id: it.id,
          name: "article"
        }
      });
    },
    //一次浏览
    //获取数据
    async initList() {
      let query = Object.assign({}, this.listQuery);
      let res = await article_list(query);
      let result = res.data;
      if (result.status == 100) {
        this.dataList = result.data.rows;
        this.articleType = result.data.articleType
        this.dataList.map(item => {
          let regex = /<[^<>]+>/g;
          item.article_content = item.article_content.replace(regex, "");
        });
        this.total = result.data.results;
        if (!this.total) {
          this.isNoData = true;
        }
      }
      this.loading = false;
      if (result.data.results <= this.dataList.length) {
        this.finished = true;
      }
    },
    onLoad() {
      setTimeout(() => {
        this.listQuery.limit += 2;
        this.initList();
      }, 1000);
    }
  },
  created: function() {
    this.typeName = this.$route.query.name;
    this.banner_path = this.$route.query.banner_path;
    this.initList();
  }
};
</script>
<style lang="scss" scoped>
.wapper-box {
  position: absolute;
  top: 0;
  left: 0px;
  right: 0px;
  bottom: 10px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.title {
  position: relative;
  background: #fff;
  img {
    width: 100%;
  }
  .typeName {
    position: absolute;
    bottom: 40%;
    left: 5%;
    font-size: 18px;
    color: #ffffff;
  }
}
.search {
  position: absolute;
  width: 100%;
  top: 1%;
  left: 10%;
  z-index: 2;
  background: #fff;
  width: 80%;
  border-radius: 15px;
  text-align: center;
  padding: 5px 0;
  input {
    // margin-top: 10px;
    font-size: 13px;
  }
  .icon-sousuo {
    vertical-align: middle;
    font-size: 18px;
    color: #999;
  }
}

.tab-box {
  padding: 0px 0 45px;
  z-index: 1;
  .icon-paixu {
    font-size: 12px;
  }
}

.dict_text {
  margin-top: 3px;
  color: #a0a0a0;
  font-size: 12px;
  white-space: normal;
  width: 200px;
  overflow: hidden;
  -webkit-line-clamp: 3;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
}

.content-box {
  background-color: #fff;
  .content-title {
    min-width: 182px;
    color: #3a3a3a;
    font-size: 14px;
  }
  .content-middle {
    color: #a0a0a0;
    font-size: 12px;
    line-height: 16px;
    padding: 5px 0 0;
  }
  .title-user {
    padding-left: 2px;
  }
  .content-img {
    width: 133px;
    height: 75px;
    margin-left: 10px;
    border-radius: 6px;
    overflow: hidden;
  }
}

.topic {
  background: #fff;
  padding: 8px 0px;
  display: -webkit-box;
  overflow: scroll;
  .topic_list:nth-child(odd) {
    margin-left: 11px;
  }
  .topic_list {
    padding-left: 3px;
    margin-left: 10px;
    display: flex;
    justify-content: space-between;
    width: 170px;
    img {
      height: 45px;
    }
    p {
      padding-top: 13px;
      font-size: 12px;
    }
  }
}

.header {
  display: flex;
  .name {
    .photo {
      width: 40px;
      height: 40px;
      border-radius: 50%;
    }
  }
  .date {
    margin-left: 10px;
    margin-top: 9px;
    .dateName {
      font-size: 13px;
    }
    .van-cell {
      line-height: 0 !important;
    }
    .dateTime {
      color: #a0a0a0;
      font-size: 11px;
    }
  }
}

.stick {
  font-size: 10px;
  padding: 0px 6px;
  color: #01a0ef;
  background: #ddf3fe;
  border-radius: 5px;
}

.icon-dianzan {
  font-size: 12px;
}

.icon-xiaoxi {
  font-size: 12px;
}

.title_topic {
  display: inline-flex;
  padding: 0px 9px;
  margin: 5px 0;
  background: #01a0ef;
  color: #fff;
  font-size: 10px;
  border-radius: 10px;
}
</style>
